/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('aligenie', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model PushNotificationsHeaders {
  commonHeaders?: map[string]string,
  xAcsAligenieAccessToken?: string(name='x-acs-aligenie-access-token'),
  authorization?: string(name='Authorization'),
}

model PushNotificationsRequest {
  notificationUnicastRequest?: {
    sendTarget?: {
      targetType?: string(name='TargetType', description='推送的目标类型，获取到对应设备或用户标识时的类型 - DEVICE_UNION_ID：设备unionId - DEVICE_OPEN_ID：设备openId - USER_UNION_ID：用户unionId - USER_OPEN_ID：用户openId'),
      targetIdentity?: string(name='TargetIdentity', description='推送目标类型对应的标识值。'),
    }(name='SendTarget', description='消息推送的目标信息。'),
    messageTemplateId?: string(name='MessageTemplateId', description='消息模板，在天猫精灵应用平台中申请消息模板时得到的模板id。'),
    placeHolder?: map[string]any(name='PlaceHolder', description='占位符信息，例如：模板是【你好，{nick}！】这里可以是：{"nick":"小甜甜"}'),
    encodeType?: string(name='EncodeType', description='编码类型，获取猫精的设备标识的途径有多种，不同途径对应不同的编码类型： PACKAGE_NAME：apk包名 SKILL_ID：技能id'),
    encodeKey?: string(name='EncodeKey', description='编码类型对应的值，例如：编码类型是SKILLID，其值就为webhook服务中得到的skillId；编码类似是PACKAGENAME，其值就为对应客户端app的packageName。'),
    organizationId?: string(name='OrganizationId', description='组织标识，推送类型是XX_UNION_XX时才需要配。当存在多种途径获取猫精设备或用户标识且又需要能互通的情况下需要找平台申请组织，申请通过后由平台分配得到。'),
    isDebug?: boolean(name='IsDebug', description='调试标识'),
  }(name='NotificationUnicastRequest', description='消息推送入参对象。'),
  tenantInfo?: {
    genieAppId?: string(name='GenieAppId', description='猫精应用id，【开发者平台-技能应用】创建应用后得到的应用id。'),
  }(name='TenantInfo', description='身份信息。'),
}

model PushNotificationsShrinkRequest {
  notificationUnicastRequestShrink?: string(name='NotificationUnicastRequest', description='消息推送入参对象。'),
  tenantInfoShrink?: string(name='TenantInfo', description='身份信息。'),
}

model PushNotificationsResponseBody = {
  requestId?: string(name='RequestId'),
}

model PushNotificationsResponse = {
  headers: map[string]string(name='headers'),
  body: PushNotificationsResponseBody(name='body'),
}

async function pushNotifications(request: PushNotificationsRequest): PushNotificationsResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new PushNotificationsHeaders{};
  return pushNotificationsWithOptions(request, headers, runtime);
}

async function pushNotificationsWithOptions(tmpReq: PushNotificationsRequest, headers: PushNotificationsHeaders, runtime: Util.RuntimeOptions): PushNotificationsResponse {
  Util.validateModel(tmpReq);
  var request = new PushNotificationsShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.notificationUnicastRequest)) {
    request.notificationUnicastRequestShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.notificationUnicastRequest, 'NotificationUnicastRequest', 'json');
  }
  if (!Util.isUnset(tmpReq.tenantInfo)) {
    request.tenantInfoShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.tenantInfo, 'TenantInfo', 'json');
  }
  var body : map[string]any= {};
  if (!Util.isUnset(request.notificationUnicastRequestShrink)) {
    body.NotificationUnicastRequest = request.notificationUnicastRequestShrink;
  }
  if (!Util.isUnset(request.tenantInfoShrink)) {
    body.TenantInfo = request.tenantInfoShrink;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAligenieAccessToken)) {
    realHeaders.x-acs-aligenie-access-token = headers.xAcsAligenieAccessToken;
  }
  if (!Util.isUnset(headers.authorization)) {
    realHeaders.Authorization = headers.authorization;
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  return doROARequestWithForm('PushNotifications', 'iap_1.0', 'HTTPS', 'PUT', 'AK', `/notifications`, 'json', req, runtime);
}

model WakeUpAppHeaders {
  commonHeaders?: map[string]string,
  xAcsAligenieAccessToken?: string(name='x-acs-aligenie-access-token'),
  authorization?: string(name='Authorization'),
}

model WakeUpAppRequest {
  path?: string(name='Path', description='应用拉起路径，类似在技能应用控制台中填的唤起链接。'),
  genieAppId?: string(name='GenieAppId', description='猫精应用id，控制台中创建应用后得到的应用id。'),
  targetInfo?: {
    targetType?: string(name='TargetType', description='推送目标类型，获取到对应设备标识时的类型  DEVICEUNIONID：设备unionId DEVICEOPENID：设备openId'),
    targetIdentity?: string(name='TargetIdentity', description='推送目标类型对应的标识值'),
    organizationId?: string(name='OrganizationId', description='组织标识，推送类型是XX_UNION_XX时才需要配。当存在多种途径获取猫精设备标识且又需要能互通的情况下需要找平台申请组织，申请通过后由平台分配得到。'),
    encodeType?: string(name='EncodeType', description='编码类型，获取猫精的设备标识的途径有多种，不同途径对应不同的编码类型：  PACKAGE_NAME：apk包名 SKILL_ID：技能id'),
    encodeKey?: string(name='EncodeKey', description='编码类型对应的值，例如：编码类型是SKILLID，其值就为webhook服务中得到的skillId；编码类似是PACKAGENAME，其值就为对应客户端app的packageName。'),
  }(name='TargetInfo', description='要拉起的目标设备信息。'),
  isDebug?: boolean(name='IsDebug', description='是否调试'),
}

model WakeUpAppResponseBody = {
  requestId?: string(name='RequestId'),
}

model WakeUpAppResponse = {
  headers: map[string]string(name='headers'),
  body: WakeUpAppResponseBody(name='body'),
}

async function wakeUpApp(request: WakeUpAppRequest): WakeUpAppResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new WakeUpAppHeaders{};
  return wakeUpAppWithOptions(request, headers, runtime);
}

async function wakeUpAppWithOptions(request: WakeUpAppRequest, headers: WakeUpAppHeaders, runtime: Util.RuntimeOptions): WakeUpAppResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.path)) {
    body.Path = request.path;
  }
  if (!Util.isUnset(request.genieAppId)) {
    body.GenieAppId = request.genieAppId;
  }
  if (!Util.isUnset(request.targetInfo)) {
    body.TargetInfo = request.targetInfo;
  }
  if (!Util.isUnset(request.isDebug)) {
    body.IsDebug = request.isDebug;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAligenieAccessToken)) {
    realHeaders.x-acs-aligenie-access-token = headers.xAcsAligenieAccessToken;
  }
  if (!Util.isUnset(headers.authorization)) {
    realHeaders.Authorization = headers.authorization;
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  return doROARequest('WakeUpApp', 'iap_1.0', 'HTTPS', 'PUT', 'AK', `/wakeup`, 'json', req, runtime);
}

